package cloud.lysky.java.on.design_pattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author luoly
 * @describe
 * @date 2022-08-20 11:16
 **/
//Feed类在内部维护了一个观察者列表，一条新闻到达时，它就进行通知
public class Feed implements Subject{

    private final List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        this.observers.add(observer);
    }

    @Override
    public void notifyObservers(String tweet) {
        observers.forEach(observer -> observer.notify(tweet));
    }
}